//
//  ZPwaihuDeatailCell.m
//  HCNewGoldFinger
//
//  Created by 刘琛 on 2017/6/16.
//  Copyright © 2017年 zjhcsoftios. All rights reserved.
//

#import "ZPwaihuDeatailCell.h"
#import "NetworkAddress.h"
#import "UIColor+EX.h"

@implementation ZPwaihuDeatailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.backgroundColor = [UIColor colorWithHexString:@"EFEFF4"];
        [self setupView];
    }
    return self;
}


- (void)setupView {
    

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _leftLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 13, 100, 18)];
    _leftLab.textAlignment = NSTextAlignmentRight;
    _leftLab.backgroundColor = [UIColor clearColor];
    _leftLab.font = [UIFont systemFontOfSize:14];
    _leftLab.numberOfLines = 30;
    _leftLab.tag = 991;
    [self addSubview:_leftLab];
    
    
    _rightLab = [[UILabel alloc] initWithFrame:CGRectMake(130, 14, kScreenWidth - 130 - 20, 16)];
    _rightLab.backgroundColor = [UIColor clearColor];
    _rightLab.textColor = [UIColor darkGrayColor];
    _rightLab.font = [UIFont systemFontOfSize:13];
    _rightLab.textAlignment = NSTextAlignmentLeft;
    _rightLab.numberOfLines = 30;
    _rightLab.tag = 992;
    _rightLab.userInteractionEnabled = YES;
    [self addSubview:_rightLab];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0.5)];
    line.tag = 993;
    line.backgroundColor = [UIColor colorWithHexString:@"cccccc"];
    [self addSubview:line];
}

- (void)setModel:(ZPchaxunDetailModel *)model {
    _model = model;
    _leftLab.text = _model.text;
    _rightLab.text = _model.value;
    
    
    CGRect frame = _leftLab.frame;
    CGSize size = [self calculateLabelSizeOfContent:_model.text withFont:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(100, 500)];
    frame.size.height = size.height;
    frame.size.width = 100;
    frame.origin.x = 20;
    frame.origin.y = 13;
    _leftLab.frame = frame;
    
    frame = _rightLab.frame;
    size = [self calculateLabelSizeOfContent:_model.value withFont:[UIFont systemFontOfSize:13] maxSize:CGSizeMake(kScreenWidth - 130 - 20, 500)];
    frame.size.height = size.height;
    frame.size.width = kScreenWidth - 130 - 20;
    frame.origin.x = 130;
    frame.origin.y = 14;
    _rightLab.frame = frame;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (CGSize)calculateLabelSizeOfContent:(NSString*)text withFont:(UIFont*)font maxSize:(CGSize)aMaxSize
{
    
    const CGSize defaultSize = CGSizeMake(kScreenWidth, 22);
    
    if (text == nil || text.length == 0) {
        return defaultSize;
    }
    
    CGSize labelSize = aMaxSize;
    if ([text isKindOfClass:[NSString class]]) {
        //       [text sizeWithFont:
        
        CGRect stringRect;
        
        labelSize = [text sizeWithFont:font constrainedToSize:aMaxSize lineBreakMode:NSLineBreakByWordWrapping];
        
        if ([text respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
            stringRect = [text boundingRectWithSize:aMaxSize
                                            options:NSStringDrawingUsesLineFragmentOrigin
                                         attributes:@{NSFontAttributeName:font}
                                            context:NULL];
        } else {
            CGSize stringSize;
            
            stringSize = [text sizeWithFont:font constrainedToSize:aMaxSize lineBreakMode:NSLineBreakByWordWrapping];
            
            stringRect = CGRectMake(0.0f, 0.0f, stringSize.width, stringSize.height);
        }
        labelSize = stringRect.size;
    }
    return labelSize;
}

@end
